#include <iostream>
#include <vector>

int main()
{
    int N;
    std::cin >> N;

    std::vector<int> P;
    for (int i = 0; i < N; i++)
    {
        int k;
        std::cin >> k;
        P.push_back(k);
    }

    int p_max;
    std::cin >> p_max;

    std::vector<int> dp(p_max + 1, 0);
    for (int i = 0; i < N; i++)
    {
        for (int j = p_max; j >= P[i]; j--)
        {
            dp[j] = std::max(dp[j], dp[j - P[i]] + P[i]);
        }
    }

    std::cout << dp[p_max] << std::endl;

    return 0;
}